package com.example.controller;

import com.example.data.approval.Approval;
import com.example.data.approval.ApprovalVO;
import com.example.data.leave.Leave;
import com.example.service.approval.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
public class ApprovalController {
    private ApprovalService approvalServiceImpl;
    @Autowired
    public ApprovalController(ApprovalService approvalServiceImpl){
        this.approvalServiceImpl = approvalServiceImpl;
    }
    //获得所有审批意见
    @GetMapping("/approval")
    public List<Approval> getAllApproval(){
        return approvalServiceImpl.getAllApproval();
    }
    //获得某领导审批意见
    @GetMapping("/approval/id")
    public List<Approval> getApprovalByEmpID(@RequestParam(value = "empID", required = false) Long empID,
                                          @RequestParam(value = "appID", required = false) Long appID){
        List<Long> list = Arrays.asList(empID, appID);
        return approvalServiceImpl.getApprovalByID(empID, appID);
    }
    //添加审批意见
    @PostMapping("/approval")
    public List<Approval> addApproval(@RequestBody Approval approvalInfo){
        return approvalServiceImpl.addApproval(ApprovalVO.convert(approvalInfo));
    }
    //修改某条审批意见
    @PutMapping("/approval/id")
    public List<Approval> editApproval(@RequestBody Approval approvalInfo){
        return approvalServiceImpl.editApproval(ApprovalVO.convert(approvalInfo));
    }
    //删除某条审批意见
    @DeleteMapping("/approval/id")
    public void deleteApproval(@RequestParam(value = "appID") long appID){
        approvalServiceImpl.deleteApproval(appID);
    }
}
